<?php

/**
 * i18n_message form.
 *
 * @package    lezgro
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class i18n_messageForm extends Basei18n_messageForm
{
  public function configure() {

        unset($this['updated_at'], $this['created_at'], $this['id'], $this['author']);

        $this->setWidgets(array(
            'trans_unit_id' => new sfWidgetFormInputText(),
            'i18n_language_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Language'), 'add_empty' => true)),
            'source' => new sfWidgetFormTextarea(),
            'target' => new sfWidgetFormTextarea(),
            'author_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Author'), 'add_empty' => true))
        ));

        $this->setValidators(array(
            'trans_unit_id' => new sfValidatorInteger(array('required' => false)),
            'i18n_language_id' => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Language'), 'required' => false)),
            'source' => new sfValidatorString(array('required' => false)),
            'target' => new sfValidatorString(array('required' => false)),
            'author_id' => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Author'), 'required' => false))
        ));

        $this->widgetSchema->setNameFormat('i18n_message[%s]');
    }

    public function bind(array $taintedValues = null, array $taintedFiles = null) {
        $sf_user = sfContext::getInstance()->getUser();
        if ($this->getObject()->isNew()) {
            $taintedValues['author_id'] = $sf_user->getUserProfile()->getId();
        } else {
            $taintedValues['author_id'] = $this->getObject()->getAuthorId();
        }
        return parent::bind($taintedValues, $taintedFiles);
    }
}
